package com.aliang.shopping.service.impl;

import com.aliang.shopping.common.PageResult;
import com.aliang.shopping.config.OssConfig;
import com.aliang.shopping.mapper.BannerMapper;
import com.aliang.shopping.model.converter.CommonConverter;
import com.aliang.shopping.model.dto.banner.BannerQueryDTO;
import com.aliang.shopping.model.po.Banner;
import com.aliang.shopping.model.vo.banner.BannerVO;
import com.aliang.shopping.service.BannerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author ShiBaLover
 * @description 针对表【banner(轮播图)】的数据库操作Service实现
 * @createDate 2024-12-23 19:42:57
 */
@Service
@AllArgsConstructor
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner>
        implements BannerService {
    private final CommonConverter<BannerVO> commonConverter = new CommonConverter<>();
    private final OssConfig ossConfig;

    @Override
    public PageResult<BannerVO> selectPage(BannerQueryDTO pageDTO) {
        //查询数据
        IPage<BannerVO> page = new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize());
        IPage<BannerVO> mapperPage = this.baseMapper.getPage(page, pageDTO);
        // 设置完成路径
        mapperPage.getRecords().forEach(vo ->
                vo.setImage(ossConfig.getUrl() + vo.getImage())
        );
        //转换数据
        return commonConverter.toPageResult(mapperPage);
    }
}




